#ifndef NDEFMESSAGEHANDLE_H_
#define NDEFMESSAGEHANDLE_H_

#include <ndefmessage.h>

#include "XmlFactory.h"

#include "EnumConverter.h"

class CNdefRecord;

/// Owns a message
class RNdefMessageHandle : public MXmlSerializable
    {
public:
    RNdefMessageHandle() : iMessage(NULL) {}
    
    /// Takes ownership of aMessage
    void Open(CNdefMessage * aMessage);
    void Close();
    
public: // MXmlSerializable implementation
    TDesC8 const & XmlElementName() { _LIT8(KName, "NdefMessage"); return KName; }
    void SerializeToXmlL(RXmlFactory & aFactory, TXmlEngElement & aElement);
    
private:
    CNdefMessage * iMessage;
    
private: // Helper class
    class TRecordHelper : public MXmlSerializable
        {
    public:
        TRecordHelper(CNdefRecord & aRecord, TBool aFullRecord = ETrue)
          : iRecord(aRecord)
          , iFullRecord(aFullRecord)
            {}
        
    public: // MXmlSerializable implementation
        TDesC8 const & XmlElementName() { _LIT8(KName, "NdefRecord"); return KName; }
        void SerializeToXmlL(RXmlFactory & aFactory, TXmlEngElement & aElement);
        
    private:
        // Records are owned by the message, not this helper
        CNdefRecord & iRecord;
        TBool iFullRecord;
        };
    };

#endif /* NDEFMESSAGEHANDLE_H_ */
